//app.js
import amap from '/cofig/amap-wx.js'
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
	this.GDgetLocation()
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    
  },
  globalData: {
    userInfo: null,
    cityName:"贵阳市",
	city:{},
    // 获取手机顶部距离
    statusBarHeight: wx.getSystemInfoSync()['statusBarHeight']
  },
	 //获取地址
	 GDgetLocation(){
	 	let amapPlugin = new amap.AMapWX({
	 		key: "841bcd01633c19852e6ef7dc5f7f3e9c"
	 	});
	 	const that = this
	 	amapPlugin.getRegeo({
	 		success: (data) => {
	 			console.log(data)
	 			that.globalData.cityName = data[0]
	 			wx.setStorage({
	 			    key: 'city',
	 			    data: data[0],
	 			    success: function () {
	 			        // console.log('success');
	 			    }
	 			});
	 		},
	 		fail: function(info){
	 		        //失败回调
	 		        wx.showToast({
	 		        	title:info
	 		        })
	 		      }
	 	})	
	 }, 
})